package com.ph.elec.gwt.register.client.ui;

import java.util.Arrays;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.ph.elec.gwt.register.client.VolunteerSignUp;
import com.ph.elec.gwt.util.UIUtils;

public class SecondPagePanel extends VerticalPanel {
	
	public final VolunteerHelpPanel pnlVolunteerHelp = new VolunteerHelpPanel();
	public final AddressPanel pnlAddress = new AddressPanel();
	final Button btnBack = new Button();
	final Button btnFinish = new Button();
	VolunteerSignUp parent = null;
	DeckPanel parentDeck = null;

	public SecondPagePanel(VolunteerSignUp parent) {
		this.parentDeck = parent.pnlDeck;
		this.parent = parent;
		addStyleName("Page");
		add(UIUtils.decorateBox(pnlVolunteerHelp, "Voluteer Commitment"));
		add(UIUtils.decorateBox(pnlAddress, "Locality Information"));
		
		add(UIUtils.buttonArea(Arrays.asList(new Widget[] {
				UIUtils.decorateButton(btnBack, "< Back"),
				UIUtils.decorateButton(btnFinish, "Finish >")
		})));
		btnBack.addClickHandler(new BackClickHandler());
		btnFinish.addClickHandler(new FinishClickHandler());
		setWidth("500px");
	}
	
	public class FinishClickHandler implements ClickHandler {
		
		boolean invalid = true;
		
		public void onClick(ClickEvent event) {
			invalid = false;
			if (!pnlVolunteerHelp.validate()) {
				invalid = true;
			}
			if (!pnlAddress.validate()) {
				invalid = true;
			}
			if (!invalid) {
				parent.RegisterVolunteer();
			}
		}
	}

	public class BackClickHandler implements ClickHandler {
		
		public void onClick(ClickEvent event) {
			parentDeck.showWidget(0);
		}
	}
}
